package com.xjgzinfo.usdp.service.impl;

import com.xjgzinfo.usdp.domain.BladeVisual;
import com.xjgzinfo.usdp.repository.BladeVisualRepository;
import com.xjgzinfo.usdp.service.BladeVisualService;
import com.xjgzinfo.usdp.service.dto.BladeVisualDTO;
import com.xjgzinfo.usdp.service.mapper.BladeVisualMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Optional;

/**
 * Service Implementation for managing {@link BladeVisual}.
 */
@Service
@Transactional
public class BladeVisualServiceImpl implements BladeVisualService {

    private final Logger log = LoggerFactory.getLogger(BladeVisualServiceImpl.class);

    private final BladeVisualRepository bladeVisualRepository;

    private final BladeVisualMapper bladeVisualMapper;

    public BladeVisualServiceImpl(BladeVisualRepository bladeVisualRepository, BladeVisualMapper bladeVisualMapper) {
        this.bladeVisualRepository = bladeVisualRepository;
        this.bladeVisualMapper = bladeVisualMapper;
    }

    @Override
    public BladeVisualDTO save(BladeVisualDTO bladeVisualDTO) {
        log.debug("Request to save BladeVisual : {}", bladeVisualDTO);
        BladeVisual bladeVisual = bladeVisualMapper.toEntity(bladeVisualDTO);
        bladeVisual = bladeVisualRepository.save(bladeVisual);
        return bladeVisualMapper.toDto(bladeVisual);
    }

    @Override
    @Transactional(readOnly = true)
    public Page<BladeVisualDTO> findAll(Pageable pageable) {
        log.debug("Request to get all BladeVisuals");
        return bladeVisualRepository.findAll(pageable)
                .map(bladeVisualMapper::toDto);
    }


    @Override
    @Transactional(readOnly = true)
    public Optional<BladeVisualDTO> findOne(Long id) {
        log.debug("Request to get BladeVisual : {}", id);
        return bladeVisualRepository.findById(id)
                .map(bladeVisualMapper::toDto);
    }

    @Override
    public void delete(Long id) {
        log.debug("Request to delete BladeVisual : {}", id);
        bladeVisualRepository.deleteById(id);
    }
}
